package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.LoverankMapper;
import com.qf.dao.UserMapper;
import com.qf.dto.RankDto;
import com.qf.dto.UserHead;
import com.qf.entity.Loverank;
import com.qf.service.LoveRankService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author chen
 * @version 1.0
 * @date 2019/10/24 15:29
 */
@Service
public class LoveRankServiceImpl implements LoveRankService {
    @Resource
    private LoverankMapper loverankMapper;
    @Resource
    private UserMapper userMapper;
    @Override
    public List<RankDto> getLoveRank() {
        PageHelper.startPage(1, 10);

        List<Loverank> loverankList = loverankMapper.getLoveRank();
        PageInfo<Loverank> pageInfo = new PageInfo<>(loverankList);
        List list = new ArrayList();

        for (Loverank loverank : pageInfo.getList()) {
            RankDto rankDto = new RankDto();
            rankDto.setRankscore(loverank.getRankscore());
            List<UserHead> userHeadList = userMapper.findUsersByRankId(loverank.getRankid());

            rankDto.setUserHeadList(userHeadList);
            list.add(rankDto);
        }
        return list;
    }
}
